package com.homegoods.designer.ui.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.homegoods.designer.R;
import com.homegoods.designer.databinding.DesignerActivityEditDesignCaseBinding;
import com.homegoods.designer.util.GetOptionsUtil;
import com.homegoods.resource.pullDownMenuAdapter.CheckedTextAdapter;
import com.homegoods.aroutercomment.ARouterPath;
import com.kedll.library.base.MyBaseFragmentActivity;
import com.kedll.library.mvp.BasePresenter;

import java.util.Arrays;

/**
 * @author QiQi
 */
@Route(path = ARouterPath.PATH_EDIT_CASE_1)
public class EditDesignCaseActivity extends MyBaseFragmentActivity<DesignerActivityEditDesignCaseBinding, BasePresenter> {

    private CheckedTextAdapter adapter;
    private GetOptionsUtil getOptionsUtil;

    @Override
    public int getLayout() {
        return R.layout.designer_activity_edit_design_case;
    }

    @SuppressLint("CheckResult")
    @Override
    protected void initEvent() {
        mBinding.linearList.setOnItemClickListener((parent, view, position, id) -> adapter.setSelectionIndex(position));

        onClicked(mBinding.btnNext, o -> ARouter.getInstance()
                .build(ARouterPath.PATH_EDIT_CASE_2)
                .navigation());

        onClicked(mBinding.tvArea, o -> getOptionsUtil.show());

    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        String[] houseType = getResources().getStringArray(R.array.designer_house_type);
        adapter = new CheckedTextAdapter(this);
        adapter.addAll(Arrays.asList(houseType));
        mBinding.linearList.setAdapter(adapter);

        getOptionsUtil = new GetOptionsUtil();
        getOptionsUtil.setOnCallBack(result -> mBinding.tvArea.setText(result));
        getOptionsUtil.initJsonData(this);

    }

    @Override
    protected void initToolBar(Bundle savedInstanceState) {
        super.initToolBar(savedInstanceState);
        setTitle("编辑作品");
    }

    @Override
    protected BasePresenter getPresenter() {
        return null;
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (isFinishing()) {
            getOptionsUtil.onDestroy();
        }
    }
}
